﻿

@model WebApp.Models.Company

@{
    ViewBag.Title = "Create";
}




<div class="container-fluid">
    <!-- Page Heading -->
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">
                Company
                <small>Create</small>
            </h1>
            <ol class="breadcrumb">
                <li>
                    <i class="fa fa-home"></i>  @Html.ActionLink("Home", "Index", "Home")
                </li>
                 <li>
                    <i class="fa fa-folder-open"></i>  @Html.ActionLink("Companies", "Index", "Companies")
                </li>
                <li class="active">
                    <i class="fa fa-file"></i> Create
                </li>
            </ol>
        </div>
    </div>
    <!-- /.row -->
     <div class="row">
        <div class="col-lg-12">

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Company</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.Partial("EditForm")
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-primary" />
            </div>
        </div>
    </div>
}
    </div>
 </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
     <script type="text/javascript">
     
    		var companyid = 0;
		var ObjectState = "Added";  
                                 
             var $departmentstable = {};
                                 
             var $employeetable = {};
                        $(document).ready(function () {

                $('form').submit(function () {
                    var token = $('[name=__RequestVerificationToken]').val();
                    var serializedForm = $(this).serialize();
                    var actionurl = $(this).attr('action');
                                         
                        var departments = $departmentstable.bootstrapTable('getData');
                                          
                        var employee = $employeetable.bootstrapTable('getData');
                                         
                     var newitem = {
                                                        Departments: departments ,
                                                        Employee: employee ,
                                          
                                Id: companyid,
                                                        Name: $('#Name', 'form').val(),
                                                        Address: $('#Address', 'form').val(),
                                                        City: $('#City', 'form').val(),
                                                        Province: $('#Province', 'form').val(),
                                                        RegisterDate: $('#RegisterDate', 'form').val(),
                                                        Employees: $('#Employees', 'form').val(),
                                                ObjectState:ObjectState 
                    };
                    $.ajax({
                        url: actionurl,
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify(newitem),
                        success: function (result) {
                            if (result.success) {
                                self.location = "/Companies/Index";
                            } else {
                                alert(result.err);
                            }
                            
                        },
                        error: function (result) {
                            console.log(result.statusText + result.responseText);
                            alert(result.statusText + result.responseText);
                        }
                    });
                    return false;
                    

                });
            });
          </script>


}
